package genalgoritm.managers;

import genalgoritm.factories.MutationFactory;
import genalgoritm.parametrs.ParametrizedComposite;

import java.util.ArrayList;

import org.apache.commons.math.genetics.MutationPolicy;
import org.eclipse.swt.widgets.Composite;

public class MutationManager {
	private static MutationManager instance;

	private ArrayList<MutationFactory> mutations = new ArrayList<MutationFactory>();
	
	public static MutationManager getInstance() {
		if (instance == null) {
			instance = new MutationManager();
			return instance;
		}
		return instance;
	}

	public ArrayList<String> getMutations() {
		ArrayList<String> out = new ArrayList<String>();
		for (MutationFactory c : mutations) {
			out.add(c.getName());
		}
		return out;
	}

	public void add(MutationFactory f) {
		mutations.add(f);		
	}	
	
	public MutationPolicy getPolicy(String name, Object... params){
		for (MutationFactory c : mutations) {
			if (name.equals(c.getName())) {
				return c.getPolicy(params);
			}
		}
		return null;		
	}
	
	public ParametrizedComposite getComposite(String name, Composite parent, int style){
		for (MutationFactory c : mutations) {
			if (name.equals(c.getName())) {
				return c.getComposite(parent, style);
			}
		}
		return null;		
	}
	
}
